// 整个的核心思想就是借助scan进行累计数据，最终传递给坚挺者

import Rx from "rxjs"

let increaseBtn = Rx.Observable.fromEvent(document.querySelector("#increase"), "click");
let increase = increaseBtn.map(value => acc => Object.assign({}, acc, { count: acc.count + 1 }));

let decreaseBtn = Rx.Observable.fromEvent(document.querySelector("#decrease"), "click");
let decrease = decreaseBtn.map(value => acc => Object.assign({}, acc, { count: acc.count - 1 }));

let stateChange = Rx.Observable.merge(
    decrease, increase
).scan((acc, changeFn) => { return changeFn(acc) }, { count: 0 });


stateChange.subscribe(state => {
    console.log(state.count);
})